{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8518518518518519"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn import tree\n",
    "from sklearn.datasets import load_wine\n",
    "from sklearn.model_selection import train_test_split\n",
    "wine = load_wine()\n",
    "wine.data.shape\n",
    "wine.target\n",
    "import pandas as pd\n",
    "pd.concat([pd.DataFrame(wine.data),pd.DataFrame(wine.target)],axis=1)\n",
    "wine.feature_names\n",
    "wine.target_names\n",
    "Xtrain, Xtest, Ytrain, Ytest = train_test_split(wine.data,wine.target,test_size=0.3)\n",
    "Xtrain.shape\n",
    "Xtest.shape\n",
    "Ytrain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9274193548387096"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf = tree.DecisionTreeClassifier(criterion=\"entropy\"\n",
    "                                  ,random_state=30\n",
    "                                  ,splitter='random'\n",
    "                                  ,max_depth=3\n",
    "                                 # ,min_samples_leaf=10\n",
    "                                 #,min_samples_split=10\n",
    "                                 )\n",
    "clf = clf.fit(Xtrain, Ytrain)\n",
    "score = clf.score(Xtrain, Ytrain) #返回预测的准确度accuracy\n",
    "score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8333333333333334"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "score = clf.score(Xtest, Ytest) #返回预测的准确度accuracy\n",
    "score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 2.40.1 (20161225.0304)\n",
       " -->\n",
       "<!-- Title: Tree Pages: 1 -->\n",
       "<svg width=\"770pt\" height=\"433pt\"\n",
       " viewBox=\"0.00 0.00 770.00 433.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 429)\">\n",
       "<title>Tree</title>\n",
       "<polygon fill=\"#ffffff\" stroke=\"transparent\" points=\"-4,4 -4,-429 766,-429 766,4 -4,4\"/>\n",
       "<!-- 0 -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>0</title>\n",
       "<path fill=\"#eefdf4\" stroke=\"#000000\" d=\"M460,-425C460,-425 348,-425 348,-425 342,-425 336,-419 336,-413 336,-413 336,-354 336,-354 336,-348 342,-342 348,-342 348,-342 460,-342 460,-342 466,-342 472,-348 472,-354 472,-354 472,-413 472,-413 472,-419 466,-425 460,-425\"/>\n",
       "<text text-anchor=\"middle\" x=\"404\" y=\"-409.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">类黄酮 &lt;= 1.714</text>\n",
       "<text text-anchor=\"middle\" x=\"404\" y=\"-394.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">entropy = 1.558</text>\n",
       "<text text-anchor=\"middle\" x=\"404\" y=\"-379.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">samples = 124</text>\n",
       "<text text-anchor=\"middle\" x=\"404\" y=\"-364.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">value = [43, 50, 31]</text>\n",
       "<text text-anchor=\"middle\" x=\"404\" y=\"-349.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">class = 雪莉</text>\n",
       "</g>\n",
       "<!-- 1 -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>1</title>\n",
       "<path fill=\"#ba92f1\" stroke=\"#000000\" d=\"M407.5,-306C407.5,-306 204.5,-306 204.5,-306 198.5,-306 192.5,-300 192.5,-294 192.5,-294 192.5,-235 192.5,-235 192.5,-229 198.5,-223 204.5,-223 204.5,-223 407.5,-223 407.5,-223 413.5,-223 419.5,-229 419.5,-235 419.5,-235 419.5,-294 419.5,-294 419.5,-300 413.5,-306 407.5,-306\"/>\n",
       "<text text-anchor=\"middle\" x=\"306\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">od280/od315稀释葡萄酒 &lt;= 2.063</text>\n",
       "<text text-anchor=\"middle\" x=\"306\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">entropy = 0.894</text>\n",
       "<text text-anchor=\"middle\" x=\"306\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">samples = 45</text>\n",
       "<text text-anchor=\"middle\" x=\"306\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">value = [0, 14, 31]</text>\n",
       "<text text-anchor=\"middle\" x=\"306\" y=\"-230.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">class = 贝尔摩德</text>\n",
       "</g>\n",
       "<!-- 0&#45;&gt;1 -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>0&#45;&gt;1</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M369.7244,-341.8796C362.3816,-332.9633 354.5524,-323.4565 346.9854,-314.268\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"349.4808,-311.7924 340.4219,-306.2981 344.0773,-316.2424 349.4808,-311.7924\"/>\n",
       "<text text-anchor=\"middle\" x=\"338.0138\" y=\"-327.4818\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">True</text>\n",
       "</g>\n",
       "<!-- 6 -->\n",
       "<g id=\"node7\" class=\"node\">\n",
       "<title>6</title>\n",
       "<path fill=\"#fbeadf\" stroke=\"#000000\" d=\"M554,-306C554,-306 450,-306 450,-306 444,-306 438,-300 438,-294 438,-294 438,-235 438,-235 438,-229 444,-223 450,-223 450,-223 554,-223 554,-223 560,-223 566,-229 566,-235 566,-235 566,-294 566,-294 566,-300 560,-306 554,-306\"/>\n",
       "<text text-anchor=\"middle\" x=\"502\" y=\"-290.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">脯氨酸 &lt;= 459.54</text>\n",
       "<text text-anchor=\"middle\" x=\"502\" y=\"-275.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">entropy = 0.994</text>\n",
       "<text text-anchor=\"middle\" x=\"502\" y=\"-260.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">samples = 79</text>\n",
       "<text text-anchor=\"middle\" x=\"502\" y=\"-245.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">value = [43, 36, 0]</text>\n",
       "<text text-anchor=\"middle\" x=\"502\" y=\"-230.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">class = 琴酒</text>\n",
       "</g>\n",
       "<!-- 0&#45;&gt;6 -->\n",
       "<g id=\"edge6\" class=\"edge\">\n",
       "<title>0&#45;&gt;6</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M438.2756,-341.8796C445.6184,-332.9633 453.4476,-323.4565 461.0146,-314.268\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"463.9227,-316.2424 467.5781,-306.2981 458.5192,-311.7924 463.9227,-316.2424\"/>\n",
       "<text text-anchor=\"middle\" x=\"469.9862\" y=\"-327.4818\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">False</text>\n",
       "</g>\n",
       "<!-- 2 -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>2</title>\n",
       "<path fill=\"#9254e9\" stroke=\"#000000\" d=\"M230.5,-187C230.5,-187 27.5,-187 27.5,-187 21.5,-187 15.5,-181 15.5,-175 15.5,-175 15.5,-116 15.5,-116 15.5,-110 21.5,-104 27.5,-104 27.5,-104 230.5,-104 230.5,-104 236.5,-104 242.5,-110 242.5,-116 242.5,-116 242.5,-175 242.5,-175 242.5,-181 236.5,-187 230.5,-187\"/>\n",
       "<text text-anchor=\"middle\" x=\"129\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">od280/od315稀释葡萄酒 &lt;= 1.516</text>\n",
       "<text text-anchor=\"middle\" x=\"129\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">entropy = 0.533</text>\n",
       "<text text-anchor=\"middle\" x=\"129\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">samples = 33</text>\n",
       "<text text-anchor=\"middle\" x=\"129\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">value = [0, 4, 29]</text>\n",
       "<text text-anchor=\"middle\" x=\"129\" y=\"-111.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">class = 贝尔摩德</text>\n",
       "</g>\n",
       "<!-- 1&#45;&gt;2 -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>1&#45;&gt;2</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M244.094,-222.8796C229.677,-213.1868 214.222,-202.7961 199.4656,-192.8752\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"201.1227,-189.7718 190.8711,-187.0969 197.2171,-195.581 201.1227,-189.7718\"/>\n",
       "</g>\n",
       "<!-- 5 -->\n",
       "<g id=\"node6\" class=\"node\">\n",
       "<title>5</title>\n",
       "<path fill=\"#61ea9a\" stroke=\"#000000\" d=\"M369,-179.5C369,-179.5 273,-179.5 273,-179.5 267,-179.5 261,-173.5 261,-167.5 261,-167.5 261,-123.5 261,-123.5 261,-117.5 267,-111.5 273,-111.5 273,-111.5 369,-111.5 369,-111.5 375,-111.5 381,-117.5 381,-123.5 381,-123.5 381,-167.5 381,-167.5 381,-173.5 375,-179.5 369,-179.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"321\" y=\"-164.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">entropy = 0.65</text>\n",
       "<text text-anchor=\"middle\" x=\"321\" y=\"-149.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">samples = 12</text>\n",
       "<text text-anchor=\"middle\" x=\"321\" y=\"-134.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">value = [0, 10, 2]</text>\n",
       "<text text-anchor=\"middle\" x=\"321\" y=\"-119.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">class = 雪莉</text>\n",
       "</g>\n",
       "<!-- 1&#45;&gt;5 -->\n",
       "<g id=\"edge5\" class=\"edge\">\n",
       "<title>1&#45;&gt;5</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M311.2463,-222.8796C312.5908,-212.2134 314.0418,-200.7021 315.4032,-189.9015\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"318.8964,-190.1742 316.6746,-179.8149 311.9514,-189.2987 318.8964,-190.1742\"/>\n",
       "</g>\n",
       "<!-- 3 -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>3</title>\n",
       "<path fill=\"#8139e5\" stroke=\"#000000\" d=\"M108,-68C108,-68 12,-68 12,-68 6,-68 0,-62 0,-56 0,-56 0,-12 0,-12 0,-6 6,0 12,0 12,0 108,0 108,0 114,0 120,-6 120,-12 120,-12 120,-56 120,-56 120,-62 114,-68 108,-68\"/>\n",
       "<text text-anchor=\"middle\" x=\"60\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">entropy = 0.0</text>\n",
       "<text text-anchor=\"middle\" x=\"60\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">samples = 10</text>\n",
       "<text text-anchor=\"middle\" x=\"60\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">value = [0, 0, 10]</text>\n",
       "<text text-anchor=\"middle\" x=\"60\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">class = 贝尔摩德</text>\n",
       "</g>\n",
       "<!-- 2&#45;&gt;3 -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>2&#45;&gt;3</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M103.3069,-103.9815C97.8469,-95.1585 92.0716,-85.8258 86.5793,-76.9506\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"89.442,-74.9254 81.2035,-68.2637 83.4896,-78.609 89.442,-74.9254\"/>\n",
       "</g>\n",
       "<!-- 4 -->\n",
       "<g id=\"node5\" class=\"node\">\n",
       "<title>4</title>\n",
       "<path fill=\"#9c63ea\" stroke=\"#000000\" d=\"M246,-68C246,-68 150,-68 150,-68 144,-68 138,-62 138,-56 138,-56 138,-12 138,-12 138,-6 144,0 150,0 150,0 246,0 246,0 252,0 258,-6 258,-12 258,-12 258,-56 258,-56 258,-62 252,-68 246,-68\"/>\n",
       "<text text-anchor=\"middle\" x=\"198\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">entropy = 0.667</text>\n",
       "<text text-anchor=\"middle\" x=\"198\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">samples = 23</text>\n",
       "<text text-anchor=\"middle\" x=\"198\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">value = [0, 4, 19]</text>\n",
       "<text text-anchor=\"middle\" x=\"198\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">class = 贝尔摩德</text>\n",
       "</g>\n",
       "<!-- 2&#45;&gt;4 -->\n",
       "<g id=\"edge4\" class=\"edge\">\n",
       "<title>2&#45;&gt;4</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M154.6931,-103.9815C160.1531,-95.1585 165.9284,-85.8258 171.4207,-76.9506\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"174.5104,-78.609 176.7965,-68.2637 168.558,-74.9254 174.5104,-78.609\"/>\n",
       "</g>\n",
       "<!-- 7 -->\n",
       "<g id=\"node8\" class=\"node\">\n",
       "<title>7</title>\n",
       "<path fill=\"#39e581\" stroke=\"#000000\" d=\"M536,-179.5C536,-179.5 440,-179.5 440,-179.5 434,-179.5 428,-173.5 428,-167.5 428,-167.5 428,-123.5 428,-123.5 428,-117.5 434,-111.5 440,-111.5 440,-111.5 536,-111.5 536,-111.5 542,-111.5 548,-117.5 548,-123.5 548,-123.5 548,-167.5 548,-167.5 548,-173.5 542,-179.5 536,-179.5\"/>\n",
       "<text text-anchor=\"middle\" x=\"488\" y=\"-164.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">entropy = 0.0</text>\n",
       "<text text-anchor=\"middle\" x=\"488\" y=\"-149.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">samples = 20</text>\n",
       "<text text-anchor=\"middle\" x=\"488\" y=\"-134.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">value = [0, 20, 0]</text>\n",
       "<text text-anchor=\"middle\" x=\"488\" y=\"-119.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">class = 雪莉</text>\n",
       "</g>\n",
       "<!-- 6&#45;&gt;7 -->\n",
       "<g id=\"edge7\" class=\"edge\">\n",
       "<title>6&#45;&gt;7</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M497.1035,-222.8796C495.8486,-212.2134 494.4944,-200.7021 493.2237,-189.9015\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"496.6816,-189.3375 492.0371,-179.8149 489.7295,-190.1554 496.6816,-189.3375\"/>\n",
       "</g>\n",
       "<!-- 8 -->\n",
       "<g id=\"node9\" class=\"node\">\n",
       "<title>8</title>\n",
       "<path fill=\"#efb083\" stroke=\"#000000\" d=\"M687.5,-187C687.5,-187 578.5,-187 578.5,-187 572.5,-187 566.5,-181 566.5,-175 566.5,-175 566.5,-116 566.5,-116 566.5,-110 572.5,-104 578.5,-104 578.5,-104 687.5,-104 687.5,-104 693.5,-104 699.5,-110 699.5,-116 699.5,-116 699.5,-175 699.5,-175 699.5,-181 693.5,-187 687.5,-187\"/>\n",
       "<text text-anchor=\"middle\" x=\"633\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">脯氨酸 &lt;= 706.242</text>\n",
       "<text text-anchor=\"middle\" x=\"633\" y=\"-156.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">entropy = 0.843</text>\n",
       "<text text-anchor=\"middle\" x=\"633\" y=\"-141.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">samples = 59</text>\n",
       "<text text-anchor=\"middle\" x=\"633\" y=\"-126.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">value = [43, 16, 0]</text>\n",
       "<text text-anchor=\"middle\" x=\"633\" y=\"-111.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">class = 琴酒</text>\n",
       "</g>\n",
       "<!-- 6&#45;&gt;8 -->\n",
       "<g id=\"edge8\" class=\"edge\">\n",
       "<title>6&#45;&gt;8</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M547.8174,-222.8796C558.0294,-213.6031 568.945,-203.6874 579.4376,-194.1559\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"581.9384,-196.6127 586.987,-187.2981 577.2316,-191.4313 581.9384,-196.6127\"/>\n",
       "</g>\n",
       "<!-- 9 -->\n",
       "<g id=\"node10\" class=\"node\">\n",
       "<title>9</title>\n",
       "<path fill=\"#47e78a\" stroke=\"#000000\" d=\"M612,-68C612,-68 516,-68 516,-68 510,-68 504,-62 504,-56 504,-56 504,-12 504,-12 504,-6 510,0 516,0 516,0 612,0 612,0 618,0 624,-6 624,-12 624,-12 624,-56 624,-56 624,-62 618,-68 612,-68\"/>\n",
       "<text text-anchor=\"middle\" x=\"564\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">entropy = 0.353</text>\n",
       "<text text-anchor=\"middle\" x=\"564\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">samples = 15</text>\n",
       "<text text-anchor=\"middle\" x=\"564\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">value = [1, 14, 0]</text>\n",
       "<text text-anchor=\"middle\" x=\"564\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">class = 雪莉</text>\n",
       "</g>\n",
       "<!-- 8&#45;&gt;9 -->\n",
       "<g id=\"edge9\" class=\"edge\">\n",
       "<title>8&#45;&gt;9</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M607.3069,-103.9815C601.8469,-95.1585 596.0716,-85.8258 590.5793,-76.9506\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"593.442,-74.9254 585.2035,-68.2637 587.4896,-78.609 593.442,-74.9254\"/>\n",
       "</g>\n",
       "<!-- 10 -->\n",
       "<g id=\"node11\" class=\"node\">\n",
       "<title>10</title>\n",
       "<path fill=\"#e68742\" stroke=\"#000000\" d=\"M750,-68C750,-68 654,-68 654,-68 648,-68 642,-62 642,-56 642,-56 642,-12 642,-12 642,-6 648,0 654,0 654,0 750,0 750,0 756,0 762,-6 762,-12 762,-12 762,-56 762,-56 762,-62 756,-68 750,-68\"/>\n",
       "<text text-anchor=\"middle\" x=\"702\" y=\"-52.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">entropy = 0.267</text>\n",
       "<text text-anchor=\"middle\" x=\"702\" y=\"-37.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">samples = 44</text>\n",
       "<text text-anchor=\"middle\" x=\"702\" y=\"-22.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">value = [42, 2, 0]</text>\n",
       "<text text-anchor=\"middle\" x=\"702\" y=\"-7.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\" fill=\"#000000\">class = 琴酒</text>\n",
       "</g>\n",
       "<!-- 8&#45;&gt;10 -->\n",
       "<g id=\"edge10\" class=\"edge\">\n",
       "<title>8&#45;&gt;10</title>\n",
       "<path fill=\"none\" stroke=\"#000000\" d=\"M658.6931,-103.9815C664.1531,-95.1585 669.9284,-85.8258 675.4207,-76.9506\"/>\n",
       "<polygon fill=\"#000000\" stroke=\"#000000\" points=\"678.5104,-78.609 680.7965,-68.2637 672.558,-74.9254 678.5104,-78.609\"/>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<graphviz.files.Source at 0x1135e62d0>"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_name = ['酒精','苹果酸','灰','灰的碱性','镁','总酚','类黄酮','非黄烷类酚类','花青素','颜色强度','色调','od280/od315稀释葡萄酒','脯氨酸']\n",
    "\n",
    "import graphviz\n",
    "dot_data = tree.export_graphviz(clf\n",
    "                                ,feature_names = feature_name\n",
    "                                ,class_names=[\"琴酒\",\"雪莉\",\"贝尔摩德\"]\n",
    "                                ,filled=True\n",
    "                                ,rounded=True\n",
    "                               ) \n",
    "graph = graphviz.Source(dot_data)\n",
    "graph"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('酒精', 0.0),\n",
       " ('苹果酸', 0.0),\n",
       " ('灰', 0.0),\n",
       " ('灰的碱性', 0.1014767512954669),\n",
       " ('镁', 0.0),\n",
       " ('总酚', 0.0),\n",
       " ('类黄酮', 0.12181165959026173),\n",
       " ('非黄烷类酚类', 0.0),\n",
       " ('花青素', 0.0),\n",
       " ('颜色强度', 0.0),\n",
       " ('色调', 0.03468552670118614),\n",
       " ('od280/od315稀释葡萄酒', 0.2693026314802502),\n",
       " ('脯氨酸', 0.4727234309328351)]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf.feature_importances_\n",
    "[*zip(feature_name,clf.feature_importances_)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "UsageError: Cell magic `%%cmd` not found.\n"
     ]
    }
   ],
   "source": [
    "%%cmd\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
